package com.wash.car.web.config;

import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Set;

@Slf4j
@Configuration
@EnableScheduling
public class TaskConfiguration {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 清除所有门店排队
     */
    @Scheduled(cron = "0 0 0 * * ?")
    private void clearStoreQueue() {
        Set<String> keys = stringRedisTemplate.keys("queue:*");
        log.info("清除所有门店排队 keys={}", keys);
        if (CollectionUtil.isNotEmpty(keys)) {
            stringRedisTemplate.delete(keys);
        }
    }

}
